package cos.android.tim;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cos.android.tim.viewythread.PlaygroundView;
import cos.android.tim.utils.Utils;

public class Tim extends Activity {

	private PlaygroundView playgroundView;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.main);

		playgroundView = (PlaygroundView) findViewById(R.id.playground);
		playgroundView.setFpsTextView((TextView) findViewById(R.id.fps));
		playgroundView.setLayout((RelativeLayout) findViewById(R.id.layout));
		Bundle intent = getIntent().getExtras();
		if (intent != null) {
			int level = intent.getInt("level");
			int world = intent.getInt("world");
			playgroundView.setLevel(level);
			playgroundView.setWorld(world);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);

		menu.add(Menu.NONE, Utils.MENU_INIT, Menu.NONE, R.string.backInitStr);
		menu.add(Menu.NONE, Utils.MENU_RESET, Menu.NONE, R.string.resetStr);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case Utils.MENU_INIT:
			Intent i = new Intent(this, InitScreen.class);
			startActivity(i);
			finish();
			return true;

		case Utils.MENU_RESET:
			playgroundView.reset();
			return true;
		}
		return false;
	}
}